package com.hctforgreen.greenservice.ui.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hctforgreen.greenservice.R;
import com.hctforgreen.greenservice.model.IndustryEntity;

public class IndustryListAdapter extends BaseAdapter {

	private Activity mActivity;
	private ArrayList<IndustryEntity> mEntities = new ArrayList<IndustryEntity>();

	public ArrayList<IndustryEntity> getIndustryList() {
		return mEntities;
	}

	public IndustryListAdapter(Activity activity) {
		mActivity = activity;

		initDataLst();

	}

	private void initDataLst() {
		IndustryEntity entity = new IndustryEntity();
		entity.name = "请选择";
		entity.en_name = "";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "地产住宅";
		entity.en_name = "House";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "商业办公";
		entity.en_name = "Office";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "酒店餐饮";
		entity.en_name = "Hotel";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "交通运输";
		entity.en_name = "Traffic";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "市政机关";
		entity.en_name = "Government";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "金融通讯";
		entity.en_name = "Financial";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "医疗卫生";
		entity.en_name = "Medical";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "工业生产";
		entity.en_name = "Production";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "文体科研";
		entity.en_name = "Sports";
		mEntities.add(entity);

		entity = new IndustryEntity();
		entity.name = "其他";
		entity.en_name = "Other";
		mEntities.add(entity);
	}

	@Override
	public int getCount() {
		return mEntities.size();
	}

	@Override
	public Object getItem(int position) {
		return mEntities.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		String sIndustry = mEntities.get(position).name;
		return new MyAdapterView(mActivity, sIndustry);
	}

	class MyAdapterView extends LinearLayout {

		public MyAdapterView(Context context, String sIndustry) {
			super(context);
			this.setOrientation(HORIZONTAL);

			LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
					LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
			params.setMargins(12, 12, 12, 12);

			TextView name = new TextView(context);
			name.setText(sIndustry);
			name.setTextColor(getResources().getColor(R.color.black));
			addView(name, params);

		}

	}
}
